package cn.cjp.m3d26;

import java.util.Calendar;
import java.util.Date;

public class aCalendar {
    public static void main(String[] args) {
        //该类的静态方法getInstance返回的是该类的子类对象
        Calendar calendar1 = Calendar.getInstance();
        System.out.println(calendar1);
        System.out.println("==============");

        //获取日历字段具体值   西方月份0-11
        int year = calendar1.get(Calendar.YEAR);
        System.out.print(year+"年");
        int mouth = calendar1.get(Calendar.MONTH);
        System.out.print(mouth+"月\n");
        System.out.println("==============");

        //设置
        calendar1.set(Calendar.YEAR,22222);
        System.out.println(calendar1.get(Calendar.YEAR)+"年");
        //设置年月日
        calendar1.set(222,453,2);
        System.out.println(calendar1.get(Calendar.YEAR)+"年"+calendar1.get(Calendar.MONTH)+"月"+calendar1.get(Calendar.DATE)+"日");
        System.out.println("==============");

        //把指定字段增加指定值
        calendar1.add(Calendar.YEAR,-1);
        System.out.println(calendar1.get(Calendar.YEAR)+"年"+calendar1.get(Calendar.MONTH)+"月"+calendar1.get(Calendar.DATE)+"日");
        System.out.println("==============");

        //把日历对象转换成日期对象
        Date date = calendar1.getTime();
        System.out.println(date);
    }
}
